﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace QunYing.DAL
{
    /// <summary>
    /// 数据访问类:VipPayOrder
    /// </summary>
    public partial class VipPayOrder
    {
        public VipPayOrder()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int 缴费单ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from VipPayOrder");
            strSql.Append(" where 缴费单ID=@缴费单ID");
            SqlParameter[] parameters = {
					new SqlParameter("@缴费单ID", SqlDbType.Int,4)
};
            parameters[0].Value = 缴费单ID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(QunYing.Model.VipPayOrder model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into VipPayOrder(");
            strSql.Append("会员卡号,经销商ID,缴费金额,会员原级别,会员新级别,原到期时间,新到期时间,原服务选项,新服务选项,提交时间,审核状态,审核人,审核时间)");
            strSql.Append(" values (");
            strSql.Append("@会员卡号,@经销商ID,@缴费金额,@会员原级别,@会员新级别,@原到期时间,@新到期时间,@原服务选项,@新服务选项,@提交时间,@审核状态,@审核人,@审核时间)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@会员卡号", SqlDbType.NVarChar,30),
					new SqlParameter("@经销商ID", SqlDbType.NVarChar,30),
					new SqlParameter("@缴费金额", SqlDbType.Int,4),
					new SqlParameter("@会员原级别", SqlDbType.NVarChar,50),
					new SqlParameter("@会员新级别", SqlDbType.NVarChar,50),
					new SqlParameter("@原到期时间", SqlDbType.NVarChar,50),
					new SqlParameter("@新到期时间", SqlDbType.DateTime),
					new SqlParameter("@原服务选项", SqlDbType.NVarChar,50),
					new SqlParameter("@新服务选项", SqlDbType.NVarChar,50),
					new SqlParameter("@提交时间", SqlDbType.DateTime),
					new SqlParameter("@审核状态", SqlDbType.NVarChar,50),
					new SqlParameter("@审核人", SqlDbType.NVarChar,50),
					new SqlParameter("@审核时间", SqlDbType.DateTime)};
            parameters[0].Value = model.会员卡号;
            parameters[1].Value = model.经销商ID;
            parameters[2].Value = model.缴费金额;
            parameters[3].Value = model.会员原级别;
            parameters[4].Value = model.会员新级别;
            parameters[5].Value = model.原到期时间;
            parameters[6].Value = model.新到期时间;
            parameters[7].Value = model.原服务选项;
            parameters[8].Value = model.新服务选项;
            parameters[9].Value = model.提交时间;
            parameters[10].Value = model.审核状态;
            parameters[11].Value = model.审核人;
            parameters[12].Value = model.审核时间;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(QunYing.Model.VipPayOrder model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update VipPayOrder set ");
            strSql.Append("会员卡号=@会员卡号,");
            strSql.Append("经销商ID=@经销商ID,");
            strSql.Append("缴费金额=@缴费金额,");
            strSql.Append("会员原级别=@会员原级别,");
            strSql.Append("会员新级别=@会员新级别,");
            strSql.Append("原到期时间=@原到期时间,");
            strSql.Append("新到期时间=@新到期时间,");
            strSql.Append("原服务选项=@原服务选项,");
            strSql.Append("新服务选项=@新服务选项,");
            strSql.Append("提交时间=@提交时间,");
            strSql.Append("审核状态=@审核状态,");
            strSql.Append("审核人=@审核人,");
            strSql.Append("审核时间=@审核时间");
            strSql.Append(" where 缴费单ID=@缴费单ID");
            SqlParameter[] parameters = {
					new SqlParameter("@会员卡号", SqlDbType.NVarChar,30),
					new SqlParameter("@经销商ID", SqlDbType.NVarChar,30),
					new SqlParameter("@缴费金额", SqlDbType.Int,4),
					new SqlParameter("@会员原级别", SqlDbType.NVarChar,50),
					new SqlParameter("@会员新级别", SqlDbType.NVarChar,50),
					new SqlParameter("@原到期时间", SqlDbType.NVarChar,50),
					new SqlParameter("@新到期时间", SqlDbType.DateTime),
					new SqlParameter("@原服务选项", SqlDbType.NVarChar,50),
					new SqlParameter("@新服务选项", SqlDbType.NVarChar,50),
					new SqlParameter("@提交时间", SqlDbType.DateTime),
					new SqlParameter("@审核状态", SqlDbType.NVarChar,50),
					new SqlParameter("@审核人", SqlDbType.NVarChar,50),
					new SqlParameter("@审核时间", SqlDbType.DateTime),
					new SqlParameter("@缴费单ID", SqlDbType.Int,4)};
            parameters[0].Value = model.会员卡号;
            parameters[1].Value = model.经销商ID;
            parameters[2].Value = model.缴费金额;
            parameters[3].Value = model.会员原级别;
            parameters[4].Value = model.会员新级别;
            parameters[5].Value = model.原到期时间;
            parameters[6].Value = model.新到期时间;
            parameters[7].Value = model.原服务选项;
            parameters[8].Value = model.新服务选项;
            parameters[9].Value = model.提交时间;
            parameters[10].Value = model.审核状态;
            parameters[11].Value = model.审核人;
            parameters[12].Value = model.审核时间;
            parameters[13].Value = model.缴费单ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int 缴费单ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from VipPayOrder ");
            strSql.Append(" where 缴费单ID=@缴费单ID");
            SqlParameter[] parameters = {
					new SqlParameter("@缴费单ID", SqlDbType.Int,4)
};
            parameters[0].Value = 缴费单ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string 缴费单IDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from VipPayOrder ");
            strSql.Append(" where 缴费单ID in (" + 缴费单IDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public QunYing.Model.VipPayOrder GetModel(int 缴费单ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 缴费单ID,会员卡号,经销商ID,缴费金额,会员原级别,会员新级别,原到期时间,新到期时间,原服务选项,新服务选项,提交时间,审核状态,审核人,审核时间 from VipPayOrder ");
            strSql.Append(" where 缴费单ID=@缴费单ID");
            SqlParameter[] parameters = {
					new SqlParameter("@缴费单ID", SqlDbType.Int,4)
};
            parameters[0].Value = 缴费单ID;

            QunYing.Model.VipPayOrder model = new QunYing.Model.VipPayOrder();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["缴费单ID"] != null && ds.Tables[0].Rows[0]["缴费单ID"].ToString() != "")
                {
                    model.缴费单ID = int.Parse(ds.Tables[0].Rows[0]["缴费单ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["会员卡号"] != null && ds.Tables[0].Rows[0]["会员卡号"].ToString() != "")
                {
                    model.会员卡号 = ds.Tables[0].Rows[0]["会员卡号"].ToString();
                }
                if (ds.Tables[0].Rows[0]["经销商ID"] != null && ds.Tables[0].Rows[0]["经销商ID"].ToString() != "")
                {
                    model.经销商ID = ds.Tables[0].Rows[0]["经销商ID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["缴费金额"] != null && ds.Tables[0].Rows[0]["缴费金额"].ToString() != "")
                {
                    model.缴费金额 = int.Parse(ds.Tables[0].Rows[0]["缴费金额"].ToString());
                }
                if (ds.Tables[0].Rows[0]["会员原级别"] != null && ds.Tables[0].Rows[0]["会员原级别"].ToString() != "")
                {
                    model.会员原级别 = ds.Tables[0].Rows[0]["会员原级别"].ToString();
                }
                if (ds.Tables[0].Rows[0]["会员新级别"] != null && ds.Tables[0].Rows[0]["会员新级别"].ToString() != "")
                {
                    model.会员新级别 = ds.Tables[0].Rows[0]["会员新级别"].ToString();
                }
                if (ds.Tables[0].Rows[0]["原到期时间"] != null && ds.Tables[0].Rows[0]["原到期时间"].ToString() != "")
                {
                    model.原到期时间 = ds.Tables[0].Rows[0]["原到期时间"].ToString();
                }
                if (ds.Tables[0].Rows[0]["新到期时间"] != null && ds.Tables[0].Rows[0]["新到期时间"].ToString() != "")
                {
                    model.新到期时间 = DateTime.Parse(ds.Tables[0].Rows[0]["新到期时间"].ToString());
                }
                if (ds.Tables[0].Rows[0]["原服务选项"] != null && ds.Tables[0].Rows[0]["原服务选项"].ToString() != "")
                {
                    model.原服务选项 = ds.Tables[0].Rows[0]["原服务选项"].ToString();
                }
                if (ds.Tables[0].Rows[0]["新服务选项"] != null && ds.Tables[0].Rows[0]["新服务选项"].ToString() != "")
                {
                    model.新服务选项 = ds.Tables[0].Rows[0]["新服务选项"].ToString();
                }
                if (ds.Tables[0].Rows[0]["提交时间"] != null && ds.Tables[0].Rows[0]["提交时间"].ToString() != "")
                {
                    model.提交时间 = DateTime.Parse(ds.Tables[0].Rows[0]["提交时间"].ToString());
                }
                if (ds.Tables[0].Rows[0]["审核状态"] != null && ds.Tables[0].Rows[0]["审核状态"].ToString() != "")
                {
                    model.审核状态 = ds.Tables[0].Rows[0]["审核状态"].ToString();
                }
                if (ds.Tables[0].Rows[0]["审核人"] != null && ds.Tables[0].Rows[0]["审核人"].ToString() != "")
                {
                    model.审核人 = ds.Tables[0].Rows[0]["审核人"].ToString();
                }
                if (ds.Tables[0].Rows[0]["审核时间"] != null && ds.Tables[0].Rows[0]["审核时间"].ToString() != "")
                {
                    model.审核时间 = DateTime.Parse(ds.Tables[0].Rows[0]["审核时间"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select 缴费单ID,会员卡号,经销商ID,缴费金额,会员原级别,会员新级别,原到期时间,新到期时间,原服务选项,新服务选项,提交时间,审核状态,审核人,审核时间 ");
            strSql.Append(" FROM VipPayOrder ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" 缴费单ID,会员卡号,经销商ID,缴费金额,会员原级别,会员新级别,原到期时间,新到期时间,原服务选项,新服务选项,提交时间,审核状态,审核人,审核时间 ");
            strSql.Append(" FROM VipPayOrder ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "VipPayOrder";
            parameters[1].Value = "缴费单ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

